package com.nwpusp.display.views;

import java.util.TimerTask;  
import android.graphics.Canvas;  
import android.graphics.Color;   
import android.view.SurfaceHolder;  

public class MyTimerTask extends TimerTask{
	
	private SurfaceHolder holder = null;  
	private GameView gameView;
	      
	public MyTimerTask(GameView gameView,SurfaceHolder _holder) { 
		this.gameView = gameView;
		holder = _holder;  
	}  
	
	public void run() {  
		Canvas canvas = null; 
		gameView.tickNum ++;
	    try {             
	    	canvas = holder.lockCanvas(null);
	    	gameView.onDraw(canvas);
	        }catch (Exception e) {  
	        	e.printStackTrace();
	        }finally {  
	            if(canvas != null) {  
	                holder.unlockCanvasAndPost(canvas);  
	            }  
	        }   
	    }  
	      
	public void clearDraw() {  
		Canvas canvas = null;  
	    try {  
	    	canvas = holder.lockCanvas(null);  
	        canvas.drawColor(Color.BLACK);  
	    }catch (Exception e) {  
	           
	    }finally {  
	    	if(canvas != null) {  
	    		holder.unlockCanvasAndPost(canvas);  
	    	}  
	    }  
	}  
}
